<template>
  <div class="house-keeper">
    <van-pull-refresh
      v-model="refreshing"
      @refresh="onRefresh"
      :success-text="refreshSuccessText"
      success-duration="1200"
    >
      <van-list
        v-model="loading"
        :finished="finished"
        :finished-text="finishedText"
        @load="onLoad"
        :error.sync="error"
        error-text="请求失败，点击重新加载"
      >
        <div class="xixi">
          <van-row
            v-for="(tag, index) in personnelList"
            :key="index"
            type="flex"
            class="server-item-head"
            @click="Jump(index)"
          >
            <van-col span="6">
              <van-image :src="tag.img" />
            </van-col>
            <van-col span="18">
              <van-cell :border="false" :title="tag.name" size="large">
                <van-tag>{{ tag.price }}</van-tag>
              </van-cell>
              <van-cell>
                <van-tag
                  plain
                  round
                  type="primary"
                  v-for="(tags, i) in tag.tags"
                  :key="i"
                  >{{ tags }}</van-tag
                >

                <van-tag
                  >{{ tag.address }} | {{ tag.age }} | {{ tag.experience }} |
                  {{ tag.comment }}</van-tag
                >
              </van-cell>
            </van-col>
          </van-row>
        </div>
      </van-list>
    </van-pull-refresh>
  </div>
</template>

<script>
import { getBabySitter } from '@/api/home.js'
// import CompanyItem from '@/components/company-item'

export default {
  name: 'HouseKeeper',
  data () {
    return {
      personnelList: [],
      // 刷新
      loading: false,
      // 加载状态
      finished: false,
      // 刷新状态
      refreshing: false,
      error: false,
      // 下拉刷新成功文本提示
      refreshSuccessText: '刷新成功!',
      finishedText: '没有更多了'
    }
  },
  props: {

  },
  watch: {

  },
  components: {
    // CompanyItem
  },
  created () {
    this.onRefresh()
  },
  mounted () {
  },
  methods: {
    async onRefresh () {
      try {
        this.finishedText = '数据加载中......'
        const { data } = await getBabySitter()
        this.personnelList = data
        this.refreshSuccessText = '刷新成功!'
        this.loading = false
        this.refreshing = false
        this.finishedText = '没有更多了'
      } catch (err) {
        this.refreshSuccessText = '刷新失败!'
        this.loading = false
        this.refreshing = false
      }
    },
    onLoad () {
      this.loading = true
      try {
        this.finished = true
      } catch (err) {
        this.error = true
      }
      this.Loading = false
    },
    Jump (index) {
      const num = (index + 1) * 1
      this.$router.push(`/yuesaopage/${num}`)
    }
  }
}

</script>

<style scoped lang="less">
.house-keeper {
  overflow: hidden;
  background-color: #fff;
  border-bottom: 1px solid #f5f7f9;
  padding-bottom: 100px;
  .van-cell {
    padding: 0 5px 15px;
  }
  /deep/ .server-item-head {
    .van-image {
      padding: 17px 12px;
      width: 160px;
      height: 160px;
    }
    .van-row {
      .van-cell {
        padding: 0 !important;
        border: none;
      }
    }
  }
  .van-cell--large {
    padding-top: 17px;
  }
  .van-tag {
    padding: 5px;
    margin-right: 20px;
    margin-top: 0px;
  }
  .van-tag--default {
    margin-right: 32px;
    background: #fff;
    color: #969799;
  }
}
</style>
